package string_question.leecode.test3;

import java.util.HashSet;

/**
 * @author code_yc
 * @version 1.0
 * @date 2020/7/6 17:03
 */
public class Solution2 {

    // 方法二：直接使用数组代替Set
    public int lengthOfLongestSubstring(String s) {
        if (s == null || s.length() == 0) return 0;
        int[] temp = new int[128];
        int l = 0, r = 0, res = 1;
        char c = ' ';
        while (r < s.length()) {
            c = s.charAt(r);
            if (temp[c] != 0) {
                res = Math.max(r - l, res);
                temp[s.charAt(l++)]--;
            } else {
                temp[c]++;
                r++;
            }
        }
        res = Math.max(res, r - l);   // 注意：这一步忘了加了
        return res;
    }
}
